package com.cw.jeeyt.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cw.jeeyt.service.bo.system.SystemTemplateModuleListBo;
import com.cw.jeeyt.service.converter.system.SystemTemplateModuleListConverter;
import com.cw.jeeyt.dao.intf.system.SystemTemplateModuleListDao;
import com.cw.jeeyt.dao.model.system.SystemTemplateModuleListDo;
import com.cw.jeeyt.dao.query.system.SystemTemplateModuleListQuery;
import com.cw.jeeyt.service.intf.system.SystemTemplateModuleListService;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.mybatis.dto.PageParam;
import com.cw.lang.common.utils.SequenceTool;

/**
 * 模板模块清单接口业务实现类
 *
 * @author chenw
 * @date 2020-02-23 20:42:03
 */
@Service
public class SystemTemplateModuleListServiceImpl implements SystemTemplateModuleListService {
    @Autowired
    private SystemTemplateModuleListDao systemTemplateModuleListDao;

    /**
     * 新增模板模块清单
     *
     * @param request 条件
     * @return String
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long addSystemTemplateModuleList(SystemTemplateModuleListBo request) {
        if (request == null) {
            return null;
        }
        Long id = SequenceTool.nextLongId();
        request.setId(id);
        systemTemplateModuleListDao.insertBySelective(SystemTemplateModuleListConverter.bo2Do(request));
        return id;
    }

    /**
     * 更新模板模块清单
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean modifySystemTemplateModuleList(SystemTemplateModuleListBo request) {
        if (request == null) {
            return false;
        }
        systemTemplateModuleListDao.updateBySelective(SystemTemplateModuleListConverter.bo2Do(request));
        return true;
    }

    /**
     * 删除模板模块清单
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteSystemTemplateModuleList(SystemTemplateModuleListBo request) {
        if (request == null) {
            return false;
        }
        return systemTemplateModuleListDao.deleteByKey(request.getId()) > 0;
    }

    /**
     * 分页查询模板模块清单
     *
     * @param request 条件
     * @return PageInfo<SystemTemplateModuleListBo>
     */
    @Override
    public PageInfo<SystemTemplateModuleListBo> selectPage(SystemTemplateModuleListBo request, PageParam pageParam){
        PageInfo<SystemTemplateModuleListDo> pageInfo = systemTemplateModuleListDao.selectPage(
            SystemTemplateModuleListQuery.builder()
                .id(request.getId())
                .moduleCode(request.getModuleCode())
                .moduleName(request.getModuleName())
                .modulePath(request.getModulePath())
                .moduleComment(request.getModuleComment())
                .build(), pageParam);
        List<SystemTemplateModuleListBo> systemTemplateModuleLists = SystemTemplateModuleListConverter.doList2BoList(
            pageInfo.getList());
        return new PageInfo<>(pageInfo, systemTemplateModuleLists);
    }

    /**
     * 查询模板模块清单详情信息
     *
     * @param request 条件
     * @return SystemTemplateModuleListBo
     */
    @Override
    public SystemTemplateModuleListBo querySystemTemplateModuleListDetail(SystemTemplateModuleListBo request) {
        if (request == null) {
            return null;
        }
        return SystemTemplateModuleListConverter.do2Bo(systemTemplateModuleListDao.selectByKey(request.getId()));
    }

    /**
     * 根据条件查询模板模块清单
     *
     * @param request 条件
     * @return List<SystemTemplateModuleListBo>
     */
    @Override
    public List<SystemTemplateModuleListBo> querySystemTemplateModuleListList(SystemTemplateModuleListBo request) {
        if (request == null) {
            return null;
        }
        return SystemTemplateModuleListConverter.doList2BoList(systemTemplateModuleListDao.selectByExample(
            SystemTemplateModuleListQuery.builder()
                .id(request.getId())
                .moduleCode(request.getModuleCode())
                .moduleName(request.getModuleName())
                .modulePath(request.getModulePath())
                .moduleComment(request.getModuleComment())
                .build()));
    }

    /**
     * 根据key查询模板模块清单
     *
     * @param id
     * @return
     */
    @Override
    public SystemTemplateModuleListBo selectByKey(Long id) {

        return SystemTemplateModuleListConverter.do2Bo(systemTemplateModuleListDao.selectByKey(id));
    }
}
